//
//  MineViewController.m
//  A段项目
//
//  Created by ～whc on 15-6-17.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MineViewController.h"

@interface MineViewController ()

@end

@implementation MineViewController

- (void)dealloc
{
    [_mineTableView release];
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"我的";
    [self createTableMine];
    [self createView];
}
#warning 创建mine的tableView
- (void)createTableMine

{
    self.mineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];
    [self.mineTableView setBackgroundColor:[UIColor whiteColor]];
    
    [self.view addSubview:self.mineTableView];
    self.mineTableView.delegate = self;
    self.mineTableView.dataSource = self;
    
}
#warning tableView顶部的登录
- (void)createView
{
    MineView *mineView = [[MineView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    mineView.enterDelegate = self;
    mineView.registerDelegate = self;
    [mineView setBackgroundColor:[UIColor clearColor]];
    self.mineTableView.tableHeaderView = mineView;
    
}

#warning tableView协议实现的方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 5;
    }
    
    return 0;
}

#warning 设置section中的高度和字体
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)] autorelease];
    
    UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor blueColor];
    headerLabel.highlightedTextColor = [UIColor yellowColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:25];
    headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
    
   if (section == 0){
        headerLabel.text = @"系统通用";
    }
    
    [customView addSubview:headerLabel];
    
    return customView;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"mineCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (indexPath.section == 0) {
        NSMutableArray *arrayName = [NSMutableArray arrayWithObjects:@"清除缓存", @"离线浏览说明",@"免责声明", @"关于我们", @"研发人员",nil];
        [cell.textLabel setText:[arrayName objectAtIndex:indexPath.row]];
        
    }
    
    return cell;
}
#warning 点击进入各个详情页面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.mineTableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        NSUInteger size = [[SDImageCache sharedImageCache]getSize];
        CGFloat mb = size / 1024.0 / 1024.0;
        NSString *string = [NSString stringWithFormat:@"当前缓存为%.2fMB", mb];
        NSLog(@"mb = %@", string);
        
        UIAlertView *clearAlert = [[UIAlertView alloc] initWithTitle:string message:@"真的要清除缓存吗?"  delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        
        [clearAlert show];
        
        
    }

    if (indexPath.row == 1) {
        FirstViewController *first = [[FirstViewController alloc] init];
        [self.navigationController pushViewController:first animated:YES];
        [first release];
    }
    if (indexPath.row == 2) {
        SecondViewController *second = [[SecondViewController alloc] init];
        [self.navigationController pushViewController:second animated:YES];
        [second release];
    }
    if (indexPath.row == 3) {
        ThirdViewController *third = [[ThirdViewController alloc] init];
        [self.navigationController pushViewController:third animated:YES];
        [third release];
    }
    if (indexPath.row == 4) {
        FourthViewController *fourth = [[FourthViewController alloc]init];
        [self.navigationController pushViewController:fourth animated:YES];
        [fourth release];
    }
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        [[SDImageCache sharedImageCache]clearDisk];
    }
}

//#warning 实现MineView中登录的协议方法
//- (void)presentEnter
//{
//    EnterViewController *enterVC = [[EnterViewController alloc] init];
//    enterVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:enterVC animated:YES];
//    [enterVC release];
//}
//#warning 实现MiveView中注册的协议方法
//- (void)presentRegister
//{
//    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
//    registerVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:registerVC animated:YES];
//    [registerVC release];
//}
//
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
